From: Jo-Philipp Wich Date: Fri, 28 Apr 2023 13:04:43 +0000 (+0200) Subject: luci-base: rpcd: handle swap entries in getBlockDevices X-Git-Url: http://git.openwrt.org/%22https:/collectd.org/%22http:/www.crowdsec.net//%22https%22/%22https:/collectd.org/%22http:/www.crowdsec.net/%22https%22?a=commitdiff_plain;h=1db30ab57076e8d249a329197eb1820d57abe23b;p=project%2Fluci.git luci-base: rpcd: handle swap entries in getBlockDevices Add entries from `/proc/swaps` to the result array as well in order to let the ui properly deal with swap files. Fixes: #6350 Signed-off-by: Jo-Philipp Wich (backported from commit ad3509bf3bb5dfa79af634c841d584408068fb0a) --- diff --git a/modules/luci-base/root/usr/libexec/rpcd/luci b/modules/luci-base/root/usr/libexec/rpcd/luci index f124512f59..7ce59a3a84 100755 --- a/modules/luci-base/root/usr/libexec/rpcd/luci +++ b/modules/luci-base/root/usr/libexec/rpcd/luci @@ -488,6 +488,30 @@ local methods = { block:close() + local swaps = io.open("/proc/swaps", "r") + if swaps then + while true do + local ln = swaps:read("*l") + if not ln then + break + end + + local dev, s = ln:match("^(/%S+)%s+%S+%s+(%d+)") + if dev and s then + rv["swap:" .. dev] = { + dev = dev:gsub("\\(%d%d%d)", + function(n) + return string.char(tonumber(n, 8)) + end), + size = s * 1024, + type = "swap" + } + end + end + + swaps:close() + end + return rv else return { error = "Unable to execute block utility" }